﻿<Page x:Class="StickyViewModelPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:ex="clr-namespace:StickyComponentExample"
    xmlns:f="http://wpfglue.wordpress.com/framework"
    Title="StickyViewModelPage">
  <Page.Resources>
    <ex:CustomerCollection x:Key="data"/>
    <DataTemplate x:Key="template" DataType="{x:Type ex:Customer}">
      <Grid x:Name="base" 
        ex:NameStickyViewModel.ViewModel="{DynamicResource viewModel}" 
            HorizontalAlignment="Stretch">
        <Grid.Resources>
          <ex:NameStickyViewModel x:Key="viewModel" 
              LastNameFirst="True" FullName="{f:StickyBinding Name}"/>
        </Grid.Resources>
        <Grid.ColumnDefinitions>
          <ColumnDefinition/>
          <ColumnDefinition/>
          <ColumnDefinition/>
        </Grid.ColumnDefinitions>
        <TextBox Text="{Binding Name, TargetNullValue='[New Customer]'}" 
                 Margin="30,0,0,0"/>
        <TextBox Grid.Column="1" Text="{Binding ElementName=base, 
          Path=(ex:NameStickyViewModel.ViewModel).LastName}"/>
        <TextBox Grid.Column="2" Text="{Binding ElementName=base, 
          Path=(ex:NameStickyViewModel.ViewModel).FirstName}"/>
      </Grid>
    </DataTemplate>
  </Page.Resources>
    <DockPanel>
    <TextBlock DockPanel.Dock="Bottom"><Hyperlink NavigateUri="StickyComponentTestPage.xaml">Test the Sticky Component Patterns</Hyperlink></TextBlock>
    <TextBlock DockPanel.Dock="Bottom"><Hyperlink NavigateUri="GarbageCollectPage.xaml">Go to Garbage Collect Page</Hyperlink></TextBlock>
    <Button x:Name="CollectButton" DockPanel.Dock="Bottom" Click="CollectButton_Click">GC.Collect</Button>
    <Button x:Name="AddButton" DockPanel.Dock="Bottom" Click="AddButton_Click" >Add Customer</Button>
    <Button x:Name="DeleteButton" DockPanel.Dock="Bottom" Click="DeleteButton_Click">Delete Customer</Button>
    <ListView x:Name="CustomerListView" ItemsSource="{StaticResource data}" ItemTemplate="{StaticResource template}">
      <ListView.ItemContainerStyle>
        <Style TargetType="ListViewItem">
          <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
        </Style>
      </ListView.ItemContainerStyle>
    </ListView>
  </DockPanel>
</Page>
